package com.example.a33mvvm.adapter;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.a33mvvm.R;
import com.example.a33mvvm.utils.ImageLoader;
import com.example.base_mvvm.entity.VideoEntity;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

public class MultiItem extends BaseMultiItemQuickAdapter<VideoEntity.DataBean, BaseViewHolder> {
    public MultiItem() {
        addItemType(0, R.layout.video_item);
        addItemType(1,R.layout.item_live);
        addItemType(2,R.layout.item_full);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, VideoEntity.DataBean dataBean) {
        StandardGSYVideoPlayer player = baseViewHolder.getView(R.id.live_gsy_player);
        player.getBackButton().setVisibility(View.GONE);
        player.setUp(dataBean.getVideopath(),true,"");
        switch (dataBean.getType()){
            case 0:
            case 2:
                setVideoOptions(baseViewHolder,dataBean);
                break;
            case 1:
                setLiveOptions(baseViewHolder,dataBean);
                break;
        }
    }
    private void setVideoOptions(BaseViewHolder baseViewHolder, VideoEntity.DataBean dataBean) {
        ImageView header = baseViewHolder.getView(R.id.item_video_header_iv);
        ImageLoader.getInstance().LoadCircleImage(getContext(),dataBean.getHeadpath(),header);
        ImageView view = baseViewHolder.getView(R.id.item_video_music_player_iv);
        ImageLoader.getInstance().LoadCircleImage(getContext(),dataBean.getHeadpath(),view);
        ObjectAnimator animator = ObjectAnimator.ofFloat(view,"Rotation",0,360);
        animator.setDuration(5000);
        animator.setRepeatCount(ValueAnimator.INFINITE);
        animator.setInterpolator(new LinearInterpolator());
        animator.start();
        baseViewHolder.setText(R.id.item_video_share_count_tv,"3.7W");
        baseViewHolder.setText(R.id.item_video_follow_count_tv,"4.2W");
        baseViewHolder.setText(R.id.item_video_comment_count_tv,"2.2W");
        baseViewHolder.setText(R.id.item_video_like_count_tv, dataBean.getLike_count()>10000?dataBean.getLike_count()/10000+"W":String.valueOf(dataBean.getLike_count()));
        if(dataBean.getGuanzhu() == 0){
            baseViewHolder.getView(R.id.item_video_add_iv).setVisibility(View.VISIBLE);
        }else {
            baseViewHolder.getView(R.id.item_video_add_iv).setVisibility(View.GONE);
        }
        if(dataBean.getDianzan() == 0){
            baseViewHolder.setImageResource(R.id.item_video_like_iv,R.drawable.ic_xihuan);
        }else {
            baseViewHolder.setImageResource(R.id.item_video_like_iv,R.drawable.ic_xihuanred);
        }
        baseViewHolder.setText(R.id.item_video_pao_tv,dataBean.getAuthname()+"的原创作品");
        baseViewHolder.setText(R.id.item_video_caption_tv,dataBean.getCaption());
        baseViewHolder.setText(R.id.item_video_username_tv,dataBean.getAuthname());
        baseViewHolder.setText(R.id.item_video_address_tv,dataBean.getAddress());
    }

    private void setLiveOptions(BaseViewHolder baseViewHolder, VideoEntity.DataBean dataBean) {
        baseViewHolder.setText(R.id.item_video_pao_tv,dataBean.getAuthname()+"的原创作品");
        baseViewHolder.setText(R.id.item_video_caption_tv,dataBean.getCaption());
        baseViewHolder.setText(R.id.item_video_username_tv,dataBean.getAuthname());
        baseViewHolder.setText(R.id.item_video_address_tv,dataBean.getAddress());
    }

}
